﻿using DataWorks_Sqlite.MappingClass;
using DataWorks_Tools.BasicMethods;
using DataWorks_Tools.CleanDetails;
using DataWorks_Tools.MappModals;
using DataWorks_Tools.ProcessExcute.ProcessReporter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataWorks_Tools.ProcessExcute.Clean
{
    public class CleanProcess
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dw_Props_Admin"></param>
        /// <param name="cleanModelforContrl">由于前端还会有线性变换的参数传过来，所以需要改变modal</param>
        /// <returns></returns>
        public static async Task<List<string>> CleanProcessExcute(dw_props_admin dw_Props_Admin, CleanModelforContrl  cleanModelforContrl)
        {
            
            var selectdatefilearray = cleanModelforContrl.selecteddirectory.ReComma().Split(',');
            var originaldatapath = cleanModelforContrl.originaldatapath.YXHPathReplace();
            var savedatapath = cleanModelforContrl.savedatapath.YXHPathReplace();
            var cleannumreg = dw_Props_Admin.clean_numreg.ReComma().Split(',');
            var cleanstringreg = dw_Props_Admin.clean_stringreg.ReComma().Split(',');
            var threadnumber = dw_Props_Admin.cleanthreadnumber;
            var ismultithreads = dw_Props_Admin.ismultithreads;
            var row = new CleanModal();
            row.taskId = cleanModelforContrl.taskId ?? Guid.NewGuid().ToString();
            row.odpath = originaldatapath;
            row.rdpath = savedatapath;
            row.datedir = selectdatefilearray;
            row.errornumber=cleannumreg;
            row.errornan=cleanstringreg;
            row.gpsspdidx = cleanModelforContrl.gpsspdidx;
            row.canspdidx= cleanModelforContrl.canspdidx;
            row.linearConvertModals = cleanModelforContrl.linearConvertModals;
            row.threadnumber = threadnumber;
            ProgressReporter.Report(row.taskId, 0, "开始执行任务...");
            if (originaldatapath != null && savedatapath != null && selectdatefilearray != null && cleannumreg != null && cleanstringreg != null)
            {
                if (ismultithreads == 1)
                {
                    var t = await CleanDetailsMethods.YXHExcuteCleanMultiThreadAsync(row);
                    return t;
                }
                else
                {
                    var t = await CleanDetailsMethods.YXHExcuteCleanMultiThreadAsync(row);
                    return t;
                }
               
            }
            else
            {
                ProgressReporter.Report(row.taskId, 101, "参数错误", true);
                return new List<string>() { "参数错误" };
                
            }
        }
    }
}
